package com.sui.bigdata.flink.sql.core.side;

import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlNode;

import java.io.Serializable;

/**
 * @author YongChen
 * @date 2019/10/21 14:13
 * @description
 * @email yong_chen@sui.com
 */
public class JoinFilterInfo implements Serializable {

    private Integer leftFieldIndex;

    private SqlKind operate;

    private String rightConstant;

    public Integer getLeftFieldIndex() {
        return leftFieldIndex;
    }

    public void setLeftFieldIndex(Integer leftFieldIndex) {
        this.leftFieldIndex = leftFieldIndex;
    }

    public SqlKind getOperate() {
        return operate;
    }

    public void setOperate(SqlKind operate) {
        this.operate = operate;
    }

    public String getRightConstant() {
        return rightConstant;
    }

    public void setRightConstant(String rightConstant) {
        this.rightConstant = rightConstant;
    }

    public boolean joinFilter (Object var1,SqlKind operate,String condition){
        switch (operate){
            case EQUALS:
                if (var1 instanceof Integer && Integer.parseInt(var1.toString()) == Integer.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof String && condition.equals(var1) ){
                    return true;
                }
                if (var1 instanceof Double && Double.parseDouble(var1.toString()) == Double.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Float && Float.parseFloat(var1.toString()) == Float.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Long && Long.parseLong(var1.toString())== Long.valueOf(condition)){
                    return true;
                }
                return false;
            case NOT_EQUALS:
                if (var1 instanceof Integer && Integer.parseInt(var1.toString()) != Integer.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof String && !condition.equals(var1) ){
                    return true;
                }
                if (var1 instanceof Double && Double.parseDouble(var1.toString()) != Double.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Float && Float.parseFloat(var1.toString()) != Float.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Long && Long.parseLong(var1.toString())!= Long.valueOf(condition)){
                    return true;
                }
                return false;
            case GREATER_THAN:
                if (var1 instanceof Integer && Integer.parseInt(var1.toString()) > Integer.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Double && Double.parseDouble(var1.toString()) > Double.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Float && Float.parseFloat(var1.toString()) > Float.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Long && Long.parseLong(var1.toString()) > Long.valueOf(condition)){
                    return true;
                }
                return false;
            case GREATER_THAN_OR_EQUAL:
                if (var1 instanceof Integer && Integer.parseInt(var1.toString()) >= Integer.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Double && Double.parseDouble(var1.toString()) >= Double.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Float && Float.parseFloat(var1.toString())>= Float.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Long && Long.parseLong(var1.toString()) >= Long.valueOf(condition)){
                    return true;
                }
                return false;
            case LESS_THAN:
                if (var1 instanceof Integer && Integer.parseInt(var1.toString()) < Integer.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Double && Double.parseDouble(var1.toString()) < Double.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Float && Float.parseFloat(var1.toString())< Float.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Long && Long.parseLong(var1.toString()) < Long.valueOf(condition)){
                    return true;
                }
                return false;
            case LESS_THAN_OR_EQUAL:
                if (var1 instanceof Integer && Integer.parseInt(var1.toString()) <= Integer.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Double && Double.parseDouble(var1.toString()) <= Double.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Float && Float.parseFloat(var1.toString()) <= Float.valueOf(condition)){
                    return true;
                }
                if (var1 instanceof Long && Long.parseLong(var1.toString()) <= Long.valueOf(condition)){
                    return true;
                }
                return false;
                default:
                    return false;
        }
    }
}
